package cn.java76.spring1.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Date;

/**
 * @author oldliu
 * @since 1.0
 */
@Service
@Aspect
public class ExecTimeWeaver {

    @Around("within(cn.java76.spring1.aop..*)")
    public Object aroud(ProceedingJoinPoint jp) throws Throwable {
        long start = System.nanoTime();
        System.out.println("方法" + jp.getSignature().getName() + " 在 " + new Date() + "被调用，参数是" + Arrays.toString(jp.getArgs()));

        Object result = jp.proceed();//放行
        System.out.println("方法【" + jp.getSignature().getName() + "】执行返回了" + result);

        long end = System.nanoTime();
        System.out.println("方法：" + jp.getSignature().getName() + "执行花费时间是"
                + (end - start) + "纳秒");
        return result;
    }
}
